package com.shd.day04;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.shd.day03.stream.Dish;

/**
 * @author S5343
 * @date 2018年7月23日下午8:52:05
 */
public class StreamMap {
	public static void main(String[] args) {
		List<Integer> arr = Arrays.asList(1, 2, 3, 4, 5, 6, 6, 7, 7, 7);
		List<Integer> collect = arr.stream().map(i -> i * 2).collect(Collectors.toList());
		System.out.println(collect); // [2, 4, 6, 8, 10, 12, 12, 14, 14, 14]

		List<String> list = listDish().stream().map(Dish::getName).collect(Collectors.toList());
		System.err.println(list);

		// flat map
		String[] srr = { "Hello", "World" };
		Stream<String[]> map = Arrays.stream(srr).map(w -> w.split(""));
		Stream<String> flatMap = map.flatMap(Arrays::stream);
		flatMap.distinct().forEach(System.out::println);

	}

	private static List<Dish> listDish() {
		List<Dish> menu = Arrays.asList(new Dish("pork", false, 800, Dish.Type.MEAT),
				new Dish("beef", false, 700, Dish.Type.MEAT), new Dish("chicken", false, 400, Dish.Type.MEAT),
				new Dish("french fries", true, 530, Dish.Type.OTHER), new Dish("rice", true, 350, Dish.Type.OTHER),
				new Dish("season fruit", true, 120, Dish.Type.OTHER), new Dish("pizza", true, 550, Dish.Type.OTHER),
				new Dish("prawns", false, 300, Dish.Type.FISH), new Dish("salmon", false, 450, Dish.Type.FISH));
		return menu;
	}
}
